/*
 * Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
 *
 * Licensed under the Apache License, Version 2.0 (the "License”);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.huaxin.hxcloud.activity;

import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.huaxin.common.BaseActivity;
import com.huaxin.common.view.SmoothImageView;
import com.huaxin.hxcloud.R;

import java.util.ArrayList;

import butterknife.BindView;


public class ImagesDetailActivity extends BaseActivity {

    public static final String INTENT_IMAGE_URL_TAG = "INTENT_IMAGE_URL_TAG";
    public static final String INTENT_IMAGE_X_TAG = "INTENT_IMAGE_X_TAG";
    public static final String INTENT_IMAGE_Y_TAG = "INTENT_IMAGE_Y_TAG";
    public static final String INTENT_IMAGE_W_TAG = "INTENT_IMAGE_W_TAG";
    public static final String INTENT_IMAGE_H_TAG = "INTENT_IMAGE_H_TAG";
    public static final String INTENT_IMAGE_POSITION = "INTENT_IMAGE_POSITION";

    @BindView(R.id.images_detail_smooth_image)
    SmoothImageView mSmoothImageView;

    private ArrayList<String> mImageUrl;
    private int mLocationX;
    private int mLocationY;
    private int mWidth;
    private int mHeight;
    private int mPosition;


    @Override
    protected void getBundleExtras(Bundle extras) {
        mImageUrl = extras.getStringArrayList(INTENT_IMAGE_URL_TAG);
        mLocationX = extras.getInt(INTENT_IMAGE_X_TAG);
        mLocationY = extras.getInt(INTENT_IMAGE_Y_TAG);
        mWidth = extras.getInt(INTENT_IMAGE_W_TAG);
        mHeight = extras.getInt(INTENT_IMAGE_H_TAG);
        mPosition = extras.getInt(INTENT_IMAGE_POSITION);
    }


    @Override
    public void onBackPressed() {
        mSmoothImageView.transformOut();
    }

    @Override
    public void onPause() {
        super.onPause();
        if (isFinishing()) {
            overridePendingTransition(0, 0);
        }
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_images_detail;
    }



    @Override
    public void initView() {
        mSmoothImageView.setMaxZoom(7f);
        mSmoothImageView.setOriginalInfo(mWidth, mHeight, mLocationX, mLocationY);
        mSmoothImageView.transformIn();
        Glide.with(this)
                .load(mImageUrl.get(mPosition))
                .apply(new RequestOptions().placeholder(R.drawable.chat_file_normal))
                .transition(new DrawableTransitionOptions().crossFade()).into(mSmoothImageView);

       /* GlideApp.with(this).load(mImageUrl.get(mPosition)).placeholder(R.drawable.chat_file_normal)
                .crossFade().into(mSmoothImageView);*/


        mSmoothImageView.setOnTransformListener(new SmoothImageView.TransformListener() {
            @Override
            public void onTransformComplete(int mode) {
                if (mode == 2) {
                    finish();
                }
            }
        });
        mSmoothImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSmoothImageView.transformOut();
            }
        });


    }




}
